package com.cskaoyan.controller;

import com.cskaoyan.bean.MarketOrder;
import com.cskaoyan.bean.bo.AdminOrderListBO;
import com.cskaoyan.bean.bo.AdminOrderRefundBO;
import com.cskaoyan.bean.bo.AdminOrderShipBO;
import com.cskaoyan.bean.bo.CommentReplyBO;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.vo.AdminOrderChannelVO;
import com.cskaoyan.bean.vo.AdminOrderDetailVO;
import com.cskaoyan.bean.vo.SimpleRespVO;
import com.cskaoyan.service.AdminCommentService;
import com.cskaoyan.service.AdminOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;

/**
 * \* User: 余雨健
 * \* Date: 2022/10/12
 * \* Time: 23:12
 **/
@RestController
@RequestMapping("admin/order")
public class AdminOrderController {

    @Autowired
    AdminOrderService adminOrderService;


    /**
     *@快递编号信息与名称
     *@author yuyujian
     *@Date 2022/10/13
     *@Time 22:18
     */

    @Autowired
    AdminCommentService adminCommentService;


    @RequestMapping("channel")
    public BaseRespVo<List<AdminOrderChannelVO>> channel() {
        List<AdminOrderChannelVO> adminOrderChannelVOS = adminOrderService.ShowChannel();
        return BaseRespVo.ok(adminOrderChannelVOS, "成功");
    }

    /**
     *@订单的显示
     *@author yuyujian
     *@Date 2022/10/13
     *@Time 22:19
     */
    @RequestMapping("list")
    public BaseRespVo<CommonData> list(AdminOrderListBO adminOrderListBO) {
        CommonData<MarketOrder> marketOrderCommonData = adminOrderService.seleteOrderList(adminOrderListBO);
        return BaseRespVo.ok(marketOrderCommonData, "成功");
    }

    /**
     *@精确查询订单id
     *@author yuyujian
     *@Date 2022/10/13
     *@Time 22:19
     */
    @RequestMapping("detail")
    public BaseRespVo<AdminOrderDetailVO> detail(Integer id) {
        AdminOrderDetailVO adminOrderDetailVO = adminOrderService.selectOrderDetail(id);
        return BaseRespVo.ok(adminOrderDetailVO, "成功");
    }

    /**
     *@删除订单
     *@author yuyujian
     *@Date 2022/10/13
     *@Time 22:20
     */
    @PostMapping("delete")
    public BaseRespVo delete(Integer orderId) {
        adminOrderService.deleteOrder(orderId);
        return BaseRespVo.ok(null, "成功");
    }

    /**
     *@为订单进行退款
     *@author yuyujian
     *@Date 2022/10/13
     *@Time 22:20
     */
    @PostMapping("refund")
    public BaseRespVo refund(@RequestBody AdminOrderRefundBO adminOrderRefundBO) {
        adminOrderService.refundOrder(adminOrderRefundBO);
        return BaseRespVo.ok(null, "成功");
    }

    /**
     *@为订单进行发货
     *@author yuyujian
     *@Date 2022/10/13
     *@Time 22:20
     */
    @PostMapping("ship")
    public BaseRespVo ship(@RequestBody AdminOrderShipBO adminOrderShipBO) {
        adminOrderService.shipOrder(adminOrderShipBO);
        return BaseRespVo.ok(null, "成功");
    }

    /**
     * 商品评论回复
     *
     * @return {@link null}
     * @author gao
     * @since 2022/10/13 20:09
     */
    @PostMapping("reply")
    public SimpleRespVO reply(@RequestBody CommentReplyBO commentReplyBO) {
        boolean ifComment = adminCommentService.reply(commentReplyBO);

        if (ifComment==true){
            return SimpleRespVO.ok(622,"订单商品已回复！");
        }else {
            return SimpleRespVO.ok(0,"成功");
        }
    }

}
